package org.jeecg.modules.kuner.bankcardbase.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.kuner.bankcardbase.entity.KrBankcardBase;
import org.jeecg.modules.kuner.bankcardbase.service.IKrBankcardBaseService;
import org.jeecg.modules.putil.LoginUserUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description:
 * @Author: Planifolia.Van
 * @Date: 2025/2/24 11:34
 */
@RestController
@Api(tags = "api-银行卡相关接口")
@RequestMapping("/api/bankcard")
public class KrBankcardBaseApiController {

    @Resource
    private LoginUserUtil loginUserUtil;
    @Resource
    private IKrBankcardBaseService bankcardBaseService;


    @ApiOperation("我的银行卡信息")
    @GetMapping("/myInfo")
    public Result<List<KrBankcardBase>> myInfo() {
        return Result.OK("查询成功！", bankcardBaseService.list(new LambdaQueryWrapper<KrBankcardBase>().eq(KrBankcardBase::getUserId, loginUserUtil.getLoginUser().getId())));
    }

    @ApiOperation("添加一条银行卡信息")
    @PostMapping("/save")
    public Result<?> save(@RequestBody KrBankcardBase bankcardBase) {
        loginUserUtil.optUserCheckerExp(bankcardBase.getUserId());
        bankcardBaseService.save(bankcardBase);
        return Result.OK("保存成功！");
    }

    @ApiOperation("删除一个银行卡信息")
    @PostMapping("/removeById/{cardId}")
    public Result<?> removeById(@PathVariable String cardId) {
        bankcardBaseService.getOptById(cardId).orElseThrow(() -> new JeecgBootException("找不到对应的银行卡信息！"));
        bankcardBaseService.removeById(cardId);
        return Result.OK("删除成功！");
    }


}
